<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录</title>
    <style>

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        section {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            width: 100%;
            /* background-color: aquamarine; */

            background-position: center;
            background-size: cover;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: url('/img/login/img.png') no-repeat center center fixed;
            background-size: cover;
            position: relative;
            overflow: hidden;
        }

        /* 添加一个半透明遮罩层增强背景效果 */
        body::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.2);
            z-index: -1;
        }

        .login-container {
            background: rgba(255, 255, 255, 0.2);
            backdrop-filter: blur(12px);
            -webkit-backdrop-filter: blur(12px);
            border-radius: 20px;
            padding: 40px;
            width: 420px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
            border: 1px solid rgba(255, 255, 255, 0.3);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }

        .login-container:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
        }

        .login-container h2 {
            text-align: center;
            margin-bottom: 30px;
            color: #fff;
            font-size: 28px;
            text-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #fff;
            font-weight: 500;
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
        }

        .form-group input {
            width: 100%;
            padding: 12px 15px;
            border: none;
            border-radius: 10px;
            background: rgba(255, 255, 255, 0.8);
            font-size: 16px;
            transition: all 0.3s ease;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }

        .form-group input:focus {
            outline: none;
            background: rgba(255, 255, 255, 0.95);
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
            transform: translateY(-2px);
        }

        .btn {
            width: 100%;
            padding: 12px;
            background: linear-gradient(45deg, #007bff, #0056b3);
            color: white;
            border: none;
            border-radius: 10px;
            cursor: pointer;
            font-size: 18px;
            font-weight: 600;
            transition: all 0.3s ease;
            box-shadow: 0 5px 15px rgba(0, 123, 255, 0.4);
            margin-top: 10px;
        }

        .btn:hover {
            background: linear-gradient(45deg, #0056b3, #004494);
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(0, 123, 255, 0.6);
        }

        .btn:active {
            transform: translateY(0);
            box-shadow: 0 3px 10px rgba(0, 123, 255, 0.4);
        }

        .message {
            text-align: center;
            margin-top: 20px;
            padding: 12px;
            border-radius: 10px;
            font-weight: 500;
            transition: all 0.3s ease;
        }

        .error {
            background: rgba(248, 215, 218, 0.8);
            color: #721c24;
            border: 1px solid rgba(245, 198, 203, 0.5);
            backdrop-filter: blur(5px);
        }

        .success {
            background: rgba(212, 237, 218, 0.8);
            color: #155724;
            border: 1px solid rgba(195, 230, 203, 0.5);
            backdrop-filter: blur(5px);
        }

        .register-link {
            text-align: center;
            margin-top: 25px;
            color: rgba(255, 255, 255, 0.9);
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
        }

        .register-link a {
            color: #b3d9ff;
            text-decoration: none;
            font-weight: 600;
            transition: all 0.3s ease;
        }

        .register-link a:hover {
            color: #fff;
            text-decoration: underline;
            text-shadow: 0 0 8px rgba(179, 217, 255, 0.8);
        }

        /* 添加一些装饰性元素增强毛玻璃效果 */
        .glass-shard {
            position: absolute;
            width: 100px;
            height: 100px;
            border-radius: 20px;
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(5px);
            z-index: -1;
            animation: float 15s infinite ease-in-out;
        }

        .glass-shard:nth-child(1) {
            top: 10%;
            left: 10%;
            animation-delay: 0s;
        }

        .glass-shard:nth-child(2) {
            top: 60%;
            right: 10%;
            animation-delay: 3s;
            width: 150px;
            height: 150px;
        }

        .glass-shard:nth-child(3) {
            bottom: 20%;
            left: 20%;
            animation-delay: 6s;
            width: 80px;
            height: 80px;
        }

        @keyframes float {
            0%, 100% {
                transform: translateY(0) rotate(0deg);
            }
            50% {
                transform: translateY(-20px) rotate(5deg);
            }
        }

        /* 响应式设计 */
        @media (max-width: 480px) {
            .login-container {
                width: 90%;
                padding: 30px 20px;
            }

            .glass-shard {
                display: none;
            }
        }
    </style>
</head>
<body>
<!-- 装饰性毛玻璃元素 -->
<div class="glass-shard"></div>
<div class="glass-shard"></div>
<div class="glass-shard"></div>
<section>
<div class="login-container">
    <h2>用户登录</h2>
    <form id="loginForm">
        <div class="form-group">
            <label for="phoneNumber">手机号</label>
            <input type="text" id="phoneNumber" name="phoneNumber" required>
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" id="password" name="password" required>
        </div>
        <button type="submit" class="btn">登录</button>
    </form>
    <div id="message"></div>
    <div class="register-link">
        <a href="forgot-password.html">忘记密码?</a>
    </div>
    <div class="register-link">
        还没有账户？<a href="register.html">立即注册</a>
    </div>
</div>
</section>

<script>
    document.getElementById('loginForm').addEventListener('submit', function(e) {
        e.preventDefault();

        const phoneNumber = document.getElementById('phoneNumber').value;
        const password = document.getElementById('password').value;

        fetch('/auth/login', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            body: `phoneNumber=${encodeURIComponent(phoneNumber)}&password=${encodeURIComponent(password)}`
        })
            .then(response => response.json())
            .then(data => {
                const messageDiv = document.getElementById('message');
                if (data.success) {
                    messageDiv.className = 'message success';
                    messageDiv.textContent = data.message;
                    // 保存用户ID到localStorage
                    if (data.data && data.data.visitorId) {
                        localStorage.setItem('cid', data.data.visitorId);
                        // 保存用户信息到localStorage
                        localStorage.setItem('userInfo', JSON.stringify(data.data));
                    }
                    // 登录成功，可以跳转到用户主页或其他页面
                    setTimeout(() => {
                        window.location.href = 'index.html?phoneNumber=' + phoneNumber;
                    }, 1000);
                } else {
                    messageDiv.className = 'message error';
                    messageDiv.textContent = data.message;
                }
            })
            .catch(error => {
                console.error('Error:', error);
                document.getElementById('message').className = 'message error';
                document.getElementById('message').textContent = '登录请求失败';
            });
    });
</script>
</body>
</html>